﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class WebShopCart : FromentWebCommon
    {
        public List<Model.view_order> list = new List<Model.view_order>();
        public string address = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {
                if (string.IsNullOrEmpty(Common.UICookie.ReadCookie("ClientUId")))
                {
                    Response.Write("<script>alert('请先登录！');window.location.href='default.aspx';</script>");
                }
                else
                {

                    int cid = Convert.ToInt32(Common.UICookie.ReadCookie("ClientUId"));
                    var umodel = Common.SqlExption.GetList<Model.tb_user>().FirstOrDefault(c => c.Id.Equals(cid));
                    address = umodel.Address;
                    var lists = Common.SqlExption.GetList<Model.tb_order>().Where(c => c.uid.Equals(cid) && c.status.Equals(1));
                    if (lists.Count() > 0)
                    {
                        list = (from c in lists
                                select new Model.view_order()
                                {
                                    buy_nums = c.buy_nums,
                                    buy_prices = c.buy_prices,
                                    create_time = c.create_time,
                                    gid = c.gid,
                                    goods_name = GetGoodsModel(c.gid) != null ? GetGoodsModel(c.gid).name : "",
                                    order_number = c.order_number,
                                    status = c.status,
                                    uid = c.uid,
                                    Id = c.Id
                                }).ToList();

                    }
                }

            }
        }

        public Model.tb_goods GetGoodsModel(int Id)
        {
            return Common.SqlExption.GetList<Model.tb_goods>().FirstOrDefault(c => c.Id.Equals(Id));
        }
    }
}